package com.crd.homeWork;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class FileDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

        //1. 获取配置⽂件对象，获取job对象实例
        Configuration conf=new Configuration();
        Job job = Job.getInstance(conf,"FileDriver");

        //2. 指定程序jar的本地路径
        job.setJarByClass(FileDriver.class);
        // 3. 指定Mapper/Reducer类
        job.setMapperClass(FileMapper.class);
        job.setReducerClass(FileReduce.class);
        //4. 指定Mapper输出的kv数据类型
        job.setMapOutputKeyClass(IntWritable.class);
        job.setMapOutputValueClass(Text.class);
        //5. 指定最终输出的kv数据类型
        job.setOutputKeyClass(IntWritable.class);
        job.setOutputValueClass(IntWritable.class);


        //6.设置ReduceTask数量
        job.setNumReduceTasks(1);
        //7. 指定job处理的原始数据路径
        FileInputFormat.setInputPaths(job,new Path("F:\\大数据学习\\作业\\模块1\\input"));//指定读取数据的原始路径
        //8. 指定job输出结果路径
        FileOutputFormat.setOutputPath(job,new Path("F:\\大数据学习\\作业\\模块1\\out"));//指定结果数据输出路径
        //9. 提交作业
        boolean flag = job.waitForCompletion(true);
        //JVM退出：正常退出0，非0值则是错误退出
        System.exit(flag?0:1);
    }
}
